package com.geega.web.core;

import lombok.Data;
import lombok.Getter;

/**
 * 统一接口数据响应
 *
 * @param <T>
 */
@Data
public class ApiResponse<T> {

    private String code;
    private String msg;
    private T data;

    private ApiResponse(String code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> ApiResponse<T> ok() {
        return new ApiResponse<>(ErrorStatus.DEFAULT_SUCCESS_CODE, ErrorStatus.DEFAULT_SUCCESS_MSG, null);
    }

    public static <T> ApiResponse<T> ok(T data) {
        return new ApiResponse<>(ErrorStatus.DEFAULT_SUCCESS_CODE, ErrorStatus.DEFAULT_SUCCESS_MSG, data);
    }

    public static <T> ApiResponse<T> fail() {
        return new ApiResponse<>(ErrorStatus.DEFAULT_ERROR_CODE, ErrorStatus.DEFAULT_ERROR_MSG, null);
    }

    public static <T> ApiResponse<T> fail(String msg) {
        return new ApiResponse<>(ErrorStatus.DEFAULT_ERROR_CODE, msg, null);
    }


    public static <T> ApiResponse<T> fail(String code, String msg) {
        return new ApiResponse<>(code, msg, null);
    }

    public static <T> ApiResponse<T> fail(String code, String msg, T data) {
        return new ApiResponse<>(code, msg, data);
    }
}
